package com.linkivr;

import java.io.InputStream;

public class LinkAdapter {

	public void logDBConf(DBConf conf) {
		GL.info(conf.driver);
		GL.info(conf.url);
		GL.info(conf.user);
		GL.info(conf.passwd);
	}

	public void logConf() {
		GL.info(G.appConf.appId);
		GL.info(G.appConf.appName);

		GL.info(G.appConf.uprun);
		GL.info(G.appConf.upcycle);
		GL.info(G.appConf.tabCall );
		GL.info(G.appConf.tabConfig );
		GL.info(G.appConf.tabService );

		logDBConf(G.appConf.upDB[0]);
		logDBConf(G.appConf.upDB[1]);
	}

	public boolean loadConf() {

		String pathName = "/appconf.properties";

		GL.info(pathName);
		InputStream ins = this.getClass().getResourceAsStream(pathName);
		if (ins == null) {
			return false;
		}

		Configuration config = new Configuration(ins);// ;
		if (config.getReady() == false) {
			return false;
		}

		G.appConf.appId = config.getIntValue("app.id");
		G.appConf.appName = config.getValue("app.name");

		G.appConf.uprun = config.getIntValue("up.runflag");
		G.appConf.upcycle = config.getIntValue("up.runcycle");
		
		G.appConf.maxCallCount = config.getIntValue("up.maxCallCount");
		G.appConf.maxReadCount = config.getIntValue("up.maxReadCount");
		G.appConf.tabCall = config.getValue("up.tabCall");
		G.appConf.tabConfig = config.getValue("up.tabConfig");
		G.appConf.tabService = config.getValue("up.tabService");

		G.appConf.upDB[0] = new DBConf();
		G.appConf.upDB[0].driver = config.getValue("up.db1.driver");
		G.appConf.upDB[0].url = config.getValue("up.db1.url");
		G.appConf.upDB[0].user = config.getValue("up.db1.user");
		G.appConf.upDB[0].passwd = config.getValue("up.db1.passwd");

		G.appConf.upDB[1] = new DBConf();
		G.appConf.upDB[1].driver = config.getValue("up.db2.driver");
		G.appConf.upDB[1].url = config.getValue("up.db2.url");
		G.appConf.upDB[1].user = config.getValue("up.db2.user");
		G.appConf.upDB[1].passwd = config.getValue("up.db2.passwd");
		logConf();

		return true;
	}

	public static void test() {

	}

	public static void main(String[] args) {
		LinkAdapter uda = new LinkAdapter();

		if (uda.loadConf() == false) {
			return;
		}

		if (G.appConf.uprun == 1) {
			UpThread ut = new UpThread("UpThread");
			ut.start();
		}
	}
}
